<template>
  <transition name="confirm-fade">
    <div class="confirm" v-show="showFlag" @click.stop>
      <div class="confirm-wrapper">
        <div class="confirm-content">
          <p>{{text}}</p>
          <div class="confirm-content_operate">
            <div @click="cancel" class="operate-btn left">{{cancelBtnText}}</div>
            <div @click="confirm" class="operate-btn">{{confirmBtnText}}</div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      text: {
        type: String,
        default: ''
      },
      confirmBtnText: {
        type: String,
        default: '确定'
      },
      cancelBtnText: {
        type: String,
        default: '取消'
      }
    },
    data() {
      return {
        showFlag: false
      }
    },
    methods: {
      show() {
        this.showFlag = true
      },
      hide() {
        this.showFlag = false
      },
      cancel() {
        this.hide()
        this.$emit('cancel')  //可能需要调用来统计取消了多少次，这里我们不用
      },
      confirm() {
        this.hide()
        this.$emit('confirm')
      }
    }
  }
</script>

<style>
/*组件整页背景*/
  .confirm{
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 998;
    background-color: rgba(7,17,27,0.5);
  }
/*弹窗的定位*/
  .confirm-wrapper{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999;
  }  
/*弹窗的内容样式*/   
  .confirm-content{
    width: 270px;
    border-radius: 13px;
    background: #fff;
  }
  .confirm-content p{
    padding: 19px 15px;
    line-height: 22px;
    text-align: center;
    font-size: 14px;
    color: black;
  }
  .confirm-content_operate{
   display: flex;
   align-items: center;
   text-align: center;
   font-size: 14px;
 }
  .operate-btn{
    flex: 1;
    line-height: 22px;
    padding: 10px 0;
    border-top: 1px solid #eee;
    color: black;
  }
  .operate-btn:last-child{
      color: #31c27c;
      border-left: 1px solid #eee;
  }
/*动画样式*/
  .confirm-fade-enter-active{
    animation: confirm-fadein 0.3s;
  }
  .confirm-fade-enter-active .confirm-content{
     animation: confirm-zoom 0.3s;
  }
  @keyframes confirm-fadein{
    0%{
      opacity: 0
    }
    100%{
      opacity: 1
    }
  }
  @keyframes confirm-zoom{
    0%{
      transform: scale(0)
    }
    50%{
      transform: scale(1.1)
    }
    100%{
      transform: scale(1)
    }
  }
</style>